package com.smh.a19exerciseDemo6;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 10, 5, 10, 50, 100, 200, 500, 800, 2, 80, 300, 700);

        MyThread myThread = new MyThread(list);
        FutureTask<ArrayList<Integer>> ft = new FutureTask<>(myThread);
        Thread thread = new Thread(ft);
        thread.setName("抽奖箱1");
        thread.start();

        //MyThread myThread2 = new MyThread(list);
        FutureTask<ArrayList<Integer>> ft1 = new FutureTask<>(myThread);
        Thread thread2 = new Thread(ft1);
        thread2.setName("抽奖箱2");
        thread2.start();

        ArrayList<Integer> list1 = ft.get();
        ArrayList<Integer> list2 = ft1.get();
        System.out.println("抽奖箱1产生了" + list1.size() + "个奖项");
        if (list2.size() != 0) {
            System.out.println("分别是:" + list1 + "最高是" + Collections.max(list1) + "元,总计为" + list1.stream().mapToInt(Integer::intValue).sum() + "元");
        }
        System.out.println("抽奖箱2产生了" + list2.size() + "个奖项");
        if (list2.size() != 0) {
            System.out.println("分别是:" + list2 + "最高是" + Collections.max(list2) + "元,总计为" + list2.stream().mapToInt(Integer::intValue).sum() + "元");
        }
        if (Collections.max(list1) > Collections.max(list2)) {
            System.out.println("抽奖箱1产生最大奖项" + Collections.max(list1));
        } else {
            System.out.println("抽奖箱2产生最大奖项" + Collections.max(list2));

        }
    }
}
